// -----------------------------------------------------------------------
//  <copyright file="RoleResourceController.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025-03-01 20:03</last-date>
// -----------------------------------------------------------------------

using DaprPlus.AspNetCore.Mvc;
using DaprPlus.AspNetCore.Mvc.Filters;
using DaprPlus.Authorization.Application.Commands;
using DaprPlus.Authorization.Application.Queries;

using Microsoft.AspNetCore.Mvc;


namespace DaprPlus.Authorization.Controllers;

[ApiResultWrapperFilter]
public abstract class RoleResourceControllerBase(IMediator mediator) : ApiControllerBase
{
    [HttpGet("access")]
    [Produces<string[]>]
    public virtual async Task<ActionResult> GetAccessCodes()
    {
        var query = new GetUserAccessCodesQuery();
        var result = await mediator.Send(query);
        return Ok(result);
    }

    [HttpPost("page")]
    [Produces<PageResult<RoleResourceOutDto>>]
    public virtual async Task<IActionResult> Page([FromBody] GetRoleResourcePageQuery query)
    {
        var page = await mediator.Send(query);
        return Ok(page);
    }

    [HttpPost("setrole")]
    [Produces<ApiResult>]
    public virtual async Task<IActionResult> SetRoleResource([FromBody] SetRoleResourceCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpPost("setfilters")]
    [Produces<ApiResult>]
    public virtual async Task<IActionResult> SetFilterGroups([FromBody] SetFilterGroupsCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }
}
